"""上传接口"""

from flask_restful import Resource
from flask_restful.reqparse import RequestParser
from werkzeug.datastructures import FileStorage
from common.res import ValidationArgs
from config import UploadConfig
# from models.user import UserModel

parse = RequestParser(ValidationArgs)
# parse.add_argument(
#     "file_type",
#     type=str,
#     choices=["image", "video", "avatar"],
#     required=True,
#     help="缺少图片类型",
#     location="args",
# )
parse.add_argument(
    "file", required=True, type=FileStorage, location="files", help="图片错误"
)


class Upload(Resource):
    def post(self):
        data = parse.parse_args()
        file = data["file"]
        UploadConfig.avatar.save(file)
        # print(f"self{self}")
        # avatar.save(file)

        # file_desc 判断如果头像存到 upload/avatar
        return "xxx"
